package leetcode.code1223;

import leetcode.IDebug;

public class Solution implements IDebug {

	int mod = (int) 1e9 + 7;

	int limit;
	int[] rollMax;

	public int dieSimulator(int n, int[] rollMax) {
		limit = n + 1;
		this.rollMax = rollMax;
		Integer[][][] dp = new Integer[n + 1][7][16];
		return this.dieSimulator(1, 0, 0, dp);
	}

	private int dieSimulator(int index, int last, int times, Integer[][][] dp) {
		if (index == limit) {
			return 1;
		}
		if (dp[index][last][times] != null) {
			return dp[index][last][times];
		}
		int ans = 0;
		for (int i = 1; i <= 6; i++) {
			if (i == last) {
				if (times + 1 <= this.rollMax[i - 1])
					ans += this.dieSimulator(index + 1, i, times + 1, dp);
			} else {
				ans += this.dieSimulator(index + 1, i, 1, dp);
			}
			ans %= mod;
		}
		dp[index][last][times] = ans;
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
